import { createVNode, render } from 'vue'

import MessageComponent from './ItMessage.vue'

const ItMessage = (options) => {
  let instance = undefined
  if (instance) {
    instance.close()
  }

  const createMessage = (options) => {
    if (typeof options === 'string') {
      options = { content: options }
    }
    let node = document.getElementById('it-message')
    if (!node) {
      node = document.createElement('div')
      node.setAttribute('id', 'it-message')
      document.body.appendChild(node)
    }
    instance = createVNode(MessageComponent, options)
    render(instance, node)
  }
  createMessage(options)
}

export default ItMessage
